﻿using System.Threading.Tasks;
using System.Windows.Input;
using Sundstrom.Mvvm.Command;

namespace Sundstrom.Mvvm.Tests.ViewModels
{
    /// <summary>
    /// Sample ViewModel.
    /// </summary>
    public sealed class MainViewModel : ViewModelBase, IMainViewModel
    {
        private string _sampleProperty;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="dialogService">Injected IDialogService.</param>
        public MainViewModel(IDialogService dialogService)
        {
            DialogService = dialogService;

            SampleProperty = "Hello World!";

            // Use RelayCommand for SampleCommand.
            SampleCommand = new RelayCommand<string>(SampleCommandImpl);
        }

        public IDialogService DialogService { get; private set; }

        /// <summary>
        /// SampleProperty
        /// </summary>
        public string SampleProperty
        {
            get { return _sampleProperty; }
            set
            {
                _sampleProperty = value;
                RaisePropertyChanged();
            }
        }

        /// <summary>
        /// SampleCommand
        /// </summary>
        public ICommand SampleCommand { get; private set; }

        /// <summary>
        /// Implementation of SampleCommand.
        /// </summary>
        /// <param name="message"></param>
        private async void SampleCommandImpl(string message)
        {
            // Call the DialogService asynchronously.
            await DialogService.ShowDialogAsync(message);
        }
    }

    public interface IMainViewModel
    {
    }

    public interface IDialogService
    {
        Task ShowDialogAsync(string message);
    }
}